﻿using Microsoft.SharePoint;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;

namespace DR5.SPExtend
{
    public static class Extensions
    {
        public const string Seprator = ";#";

        public static string ToStr(this object liObj)
        {
            string returnStr = string.Empty;
            if (liObj != null)
            {
                returnStr = liObj.ToString();
            }
            return returnStr;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="liObj"></param>
        /// <param name="returnIndexStr">Fill value, if string contains ";#" </param>
        /// <returns></returns>
        public static string ToStr(this object obj, int returnIndexStr)
        {
            string returnStr = string.Empty;
            returnStr = obj.ToStr();

            if (returnIndexStr != -1)
            {
                if (returnStr.Contains(Seprator))
                {
                    returnStr = returnStr.Split(Seprator)[returnIndexStr];
                }
            }

            return returnStr;
        }

        public static string ToStr(this object obj, string dateFormat)
        {
            string returnStr = string.Empty;
            returnStr = obj.ToStr();

            //http://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx
            DateTime dt = Convert.ToDateTime(returnStr);
            string str = dt.ToString("d");
            return str;
        }
    }
}
